package cn.sdormitory.violative.enums;

import lombok.Getter;

import java.util.Optional;

@Getter
public enum ViolationPatrolStatus {
    CREATED(1,"草稿"),SUBMIT(2,"待接受"),RECEIVE(3,"接受中"),COMPLETE(4,"完成");
    private final int value;
    private final String text;

    ViolationPatrolStatus(int value, String text) {
        this.value = value;
        this.text = text;
    }

    public static Optional<ViolationPatrolStatus> instanceOf(int value){
        ViolationPatrolStatus[] values = values();
        for(ViolationPatrolStatus v : values){
            if(v.getValue() == value){
                return Optional.of(v);
            }
        }
        return Optional.empty();
    }

    public static ViolationPatrolStatus instanceOfThrow(int value){
        Optional<ViolationPatrolStatus> optional = instanceOf(value);
        return optional.orElseThrow(()->new IllegalArgumentException("根据"+value+"创建违纪巡查状态对象失败"));
    }

}
